import re

# 单行日志
logline = '''222.88.152.77 - - [30/May/2018:16:57:57 +0800] "GET /login.html HTTP/1.1" 200 4662 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0" "-"'''


# 通过正则获取一行日志中的IP地址的信息

def main():
    ip_pattern = r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
    ip_regex = re.compile(ip_pattern)
    mo = ip_regex.search(logline)
    print(mo.group())


if __name__ == '__main__':
    main()
